package com.paotui.controller;

import cn.hutool.json.JSONUtil;
import com.paotui.common.R;
import com.paotui.pojo.Users;
import com.paotui.service.impl.UsersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/users/list")
public class UsersListController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //查询所有用户信息
        UsersServiceImpl service = new UsersServiceImpl();
        List<Users> list = service.list();
        service.getSqlSession().close();
        R r = R.success("用户信息查询成功",list);
        //list.forEach(a-> System.out.println(a));
        PrintWriter out  = response.getWriter();
        out.write(JSONUtil.toJsonStr(r));
    }
}
